
#ifndef _FIFO_H_
#define _FIFO_H_

#include <stdint.h>

typedef uint8_t elem_t;

struct kfifo {
	elem_t *buffer;	/* the buffer holding the data */
	unsigned int size;	/* the size of the allocated buffer */
	unsigned int in;	/* data is added at offset (in % size) */
	unsigned int out;	/* data is extracted from off. (out % size) */
};

typedef struct kfifo fifo_t;

static inline unsigned int Fifo_GetDataLength(fifo_t *fifo)
{
	return fifo->in - fifo->out;
}

static inline unsigned int Fifo_GetFreeSpace(fifo_t *fifo)
{
	return fifo->size - Fifo_GetDataLength(fifo);
}

static inline void Fifo_Clean(fifo_t *fifo)
{
	fifo->in = fifo->out = 0;
}

fifo_t *Fifo_Init(fifo_t *fifo, elem_t *buffer, unsigned int size);
unsigned int Fifo_GetBlock(fifo_t *fifo, elem_t *buffer, unsigned int len);
unsigned int Fifo_PutBlock(fifo_t *fifo, const elem_t *buffer, unsigned int len);
unsigned int Fifo_PutOne(fifo_t *fifo, elem_t *elem);
unsigned int Fifo_GetOne(fifo_t *fifo, elem_t *elem);


#endif
